

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/my-blog/img/fluid.png">
  <link rel="icon" href="/my-blog/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="木舟">
  <meta name="keywords" content="python Vue Test 测试开发 自动化测试">
  
    <meta name="description" content="前言我们在开发的过程中，不仅需要用到python的标准库 还常常会用到一些其他大佬写好的 第三方库 比如测试中比较常见的：  selenium requests pytest  那么，既然是第三方库，所以是需要安装才可以使用的。 安装的话，就需要用到pip，下面会先说一下pip的一些配置。 pip安装12pip install 包名pip install 包名&#x3D;&#x3D;版本号  镜像源我们使用pip时，">
<meta property="og:type" content="article">
<meta property="og:title" content="python常用第三方库">
<meta property="og:url" content="https://walker_kwu.gitee.io/my-blog/2023/03/25/python/base/python%E5%B8%B8%E7%94%A8%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%93/">
<meta property="og:site_name" content="My Blog">
<meta property="og:description" content="前言我们在开发的过程中，不仅需要用到python的标准库 还常常会用到一些其他大佬写好的 第三方库 比如测试中比较常见的：  selenium requests pytest  那么，既然是第三方库，所以是需要安装才可以使用的。 安装的话，就需要用到pip，下面会先说一下pip的一些配置。 pip安装12pip install 包名pip install 包名&#x3D;&#x3D;版本号  镜像源我们使用pip时，">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-03-25T02:36:06.000Z">
<meta property="article:modified_time" content="2023-05-23T10:37:53.265Z">
<meta property="article:author" content="木舟">
<meta property="article:tag" content="测试开发">
<meta property="article:tag" content="Python基础">
<meta name="twitter:card" content="summary_large_image">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>python常用第三方库 - My Blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/my-blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/my-blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/my-blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"walker_kwu.gitee.io","root":"/my-blog/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"left","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/my-blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/my-blog/js/utils.js" ></script>
  <script  src="/my-blog/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/my-blog/">
      <strong>木舟</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/my-blog/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="python常用第三方库"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        木舟
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-03-25 10:36" pubdate>
          2023年3月25日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          7.4k 字
        
      </span>
    

    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="padding-left: 2rem; margin-right: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">python常用第三方库</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：2023年5月23日 晚上
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>我们在开发的过程中，不仅需要用到python的标准库</p>
<p>还常常会用到一些其他大佬写好的 <strong>第三方库</strong></p>
<p>比如测试中比较常见的：</p>
<ul>
<li>selenium</li>
<li>requests</li>
<li>pytest</li>
</ul>
<p>那么，既然是第三方库，所以是需要安装才可以使用的。</p>
<p>安装的话，就需要用到pip，下面会先说一下pip的一些配置。</p>
<h1 id="pip"><a href="#pip" class="headerlink" title="pip"></a>pip</h1><h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sh">pip install 包名<br>pip install 包名==版本号<br></code></pre></td></tr></table></figure>

<h2 id="镜像源"><a href="#镜像源" class="headerlink" title="镜像源"></a>镜像源</h2><p>我们使用pip时，默认使用的是 <strong>国外的python源</strong></p>
<p>因为 <strong>某种限制</strong>， 我们访问国外的网站会十分的慢，常常会出现 <code>timeout</code></p>
<p>所以我们需要为pip配置 <strong>镜像源</strong>，来加快我们安装的速度</p>
<figure class="highlight text"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs text">国内镜像源：<br>豆瓣：https://pypi.douban.com/simple<br>阿里：https://mirrors.aliyun.com/pypi/simple<br>清华：https://pypi.tuna.tsinghua.edu.cn/simple<br>华中理工大学：https://pypi.hustunique.com/simple<br>山东理工大学：https://pypi.sdutlinux.org/simple<br>中国科学技术大学：https://pypi.mirrors.ustc.edu.cn/simple<br></code></pre></td></tr></table></figure>

<p>有两种方式。</p>
<h3 id="第一种"><a href="#第一种" class="headerlink" title="第一种"></a>第一种</h3><p>直接在安装的时候，通过 <code>-i</code> 参数指定镜像源</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs sh">pip install 包名 -i https://mirrors.aliyun.com/pypi/simple<br></code></pre></td></tr></table></figure>

<h3 id="第二种"><a href="#第二种" class="headerlink" title="第二种"></a>第二种</h3><p>直接修改pip的默认镜像源</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs sh">pip config <span class="hljs-built_in">set</span> global.index-url https://mirrors.aliyun.com/pypi/simple<br>pip install 包名<br></code></pre></td></tr></table></figure>


<h1 id="pymysql"><a href="#pymysql" class="headerlink" title="pymysql"></a>pymysql</h1><p>这个库，可以帮助我们在python中连接mysql</p>
<p><code>pip install pymysql</code></p>
<h2 id="连接并进行查询"><a href="#连接并进行查询" class="headerlink" title="连接并进行查询"></a>连接并进行查询</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pymysql<br><span class="hljs-keyword">from</span> pymysql.cursors <span class="hljs-keyword">import</span> DictCursor<br><br><span class="hljs-keyword">with</span> pymysql.Connect(<br>    host=<span class="hljs-string">&quot;127.0.0.1&quot;</span>,<br>    user=<span class="hljs-string">&quot;root&quot;</span>,<br>    password=<span class="hljs-string">&quot;123456&quot;</span>,<br>    database=<span class="hljs-string">&quot;walkertest&quot;</span>,<br>    cursorclass=DictCursor<br>) <span class="hljs-keyword">as</span> connect:<br>    cursor = connect.cursor()  <span class="hljs-comment"># 获取游标，通过游标来执行sql</span><br>    <span class="hljs-comment"># 执行sql语句</span><br>    sql = <span class="hljs-string">&quot;select * from django_migrations;&quot;</span><br>    cursor.execute(sql)  <span class="hljs-comment"># 执行sql</span><br><br>    <span class="hljs-comment"># 获取查询结果</span><br>    <span class="hljs-comment"># cursor.fetchone()获取一条数据，游标移动，再次获取时获取下一条</span><br>    <span class="hljs-comment"># print(cursor.fetchone())</span><br>    <span class="hljs-comment"># print(cursor.fetchone())</span><br><br>    <span class="hljs-comment"># cursor.fetchall()获取从游标开始到最后的所有数据</span><br>    <span class="hljs-built_in">print</span>(cursor.fetchall())<br></code></pre></td></tr></table></figure>

<h2 id="操作类的sql"><a href="#操作类的sql" class="headerlink" title="操作类的sql"></a>操作类的sql</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pymysql<br><span class="hljs-keyword">from</span> pymysql.cursors <span class="hljs-keyword">import</span> DictCursor<br><br><span class="hljs-keyword">with</span> pymysql.Connect(<br>    host=<span class="hljs-string">&quot;127.0.0.1&quot;</span>,<br>    user=<span class="hljs-string">&quot;root&quot;</span>,<br>    password=<span class="hljs-string">&quot;123456&quot;</span>,<br>    database=<span class="hljs-string">&quot;walkertest&quot;</span>,<br>    cursorclass=DictCursor<br>) <span class="hljs-keyword">as</span> connect:<br>    cursor = connect.cursor()  <span class="hljs-comment"># 获取游标，通过游标来执行sql</span><br>    <span class="hljs-comment"># 执行sql语句</span><br>    sql = <span class="hljs-string">&quot;insert into xxx () value()&quot;</span><br>    cursor.execute(sql)<br><br>    connect.commit()  <span class="hljs-comment"># 操作类的sql，使用游标执行后，必须要用connect.commit进行提交，才能够保存到数据库中</span><br></code></pre></td></tr></table></figure>

<h1 id="jsonpath"><a href="#jsonpath" class="headerlink" title="jsonpath"></a>jsonpath</h1><p>十分方便我们进行对字典的取值</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> json<br><span class="hljs-keyword">import</span> jsonpath<br>d = &#123;<br>    <span class="hljs-string">&quot;error_code&quot;</span>: <span class="hljs-number">0</span>,<br>    <span class="hljs-string">&quot;stu_info&quot;</span>:[<br>        &#123;<br>            <span class="hljs-string">&quot;id&quot;</span>: <span class="hljs-number">223</span>,<br>            <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;安妮&quot;</span>,<br>            <span class="hljs-string">&quot;sex&quot;</span>: <span class="hljs-string">&quot;女&quot;</span>,<br>            <span class="hljs-string">&quot;classname&quot;</span>: <span class="hljs-string">&quot;212期&quot;</span>,<br>            <span class="hljs-string">&quot;data&quot;</span>: &#123;<br>                <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;测试1&quot;</span>,<br>                <span class="hljs-string">&quot;data&quot;</span>: &#123;<br>                    <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;测试2&quot;</span><br>                &#125;<br>            &#125;<br>        &#125;,<br>        &#123;<br>            <span class="hljs-string">&quot;id&quot;</span>: <span class="hljs-number">224</span>,<br>            <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;景龙&quot;</span>,<br>            <span class="hljs-string">&quot;sex&quot;</span>: <span class="hljs-string">&quot;男&quot;</span>,<br>            <span class="hljs-string">&quot;classname&quot;</span>: <span class="hljs-string">&quot;212期&quot;</span><br>        &#125;,<br>        &#123;<br>            <span class="hljs-string">&quot;id&quot;</span>: <span class="hljs-number">225</span>,<br>            <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;MS226&quot;</span>,<br>            <span class="hljs-string">&quot;classname&quot;</span>: <span class="hljs-string">&quot;212期&quot;</span><br>        &#125;<br>    ]<br>&#125;<br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">type</span>(d))<br>name = d[<span class="hljs-string">&quot;stu_info&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;name&quot;</span>]<br><span class="hljs-built_in">print</span>(name)<br><span class="hljs-comment"># 模糊匹配  匹配所有学员name</span><br>data1=jsonpath.jsonpath(d, <span class="hljs-string">&quot;$..name&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;匹配所有学员name：&quot;</span>, data1)<br><span class="hljs-comment"># 精确匹配</span><br><span class="hljs-comment"># 获取安妮的值  匹配第一个学员name</span><br>data3=jsonpath.jsonpath(d, <span class="hljs-string">&quot;$.stu_info[0].name&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;匹配第一个学员name:&quot;</span>, data3)<br><span class="hljs-comment">#  匹配第一个学员下面所有的name</span><br>data4=jsonpath.jsonpath(d, <span class="hljs-string">&quot;$.stu_info[0]..name&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;匹配第一个学员name:&quot;</span>, data4)<br><span class="hljs-comment">#匹配前两个学员的信息</span><br>data=jsonpath.jsonpath(d, <span class="hljs-string">&quot;$.stu_info[:2]&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;匹配前两个学员的信息：&quot;</span>, data)<br>data5=jsonpath.jsonpath(d, <span class="hljs-string">&quot;$.stu_info[?(@.sex==&#x27;女&#x27;)]&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;匹配性别为女的学生信息:&quot;</span>, data5)<br>data6=jsonpath.jsonpath(d, <span class="hljs-string">&quot;$.stu_info[?(@.sex)]&quot;</span>)<br><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;匹配包含性别列的学生信息:&quot;</span>, data6)<br><span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">jsonpath模块处理json数据</span><br><span class="hljs-string">&quot;&quot;&quot;</span><br>json_data=<span class="hljs-string">&#x27;&#123;&quot;name&quot;:&quot;冷水&quot;,&quot;id&quot;:&quot;242&quot;&#125;&#x27;</span><br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">type</span>(json_data))<br><span class="hljs-comment"># json数据进行转化，转化字典 反序列化</span><br>d2=json.loads(json_data)<br><span class="hljs-built_in">print</span>(<span class="hljs-built_in">type</span>(d2))<br><span class="hljs-built_in">print</span>(jsonpath.jsonpath(d2, <span class="hljs-string">&#x27;$.id&#x27;</span>))<br></code></pre></td></tr></table></figure>

<h1 id="yaml"><a href="#yaml" class="headerlink" title="yaml"></a>yaml</h1><p>如今yaml文件已经慢慢的成为作为 <strong>配置文件</strong> 的主流</p>
<p>所以我们也是很有必要的学习一下python如何读取yaml配置文件</p>
<p>yaml文件, 最终生成的要么是 <strong>字典</strong> 要么是 <strong>列表</strong></p>
<p>取决于在文件根部编写的是什么符号.</p>
<p>yaml文件格式的编写方式可以参考这篇文章: <a target="_blank" rel="noopener" href="https://www.cnblogs.com/mimistudy/p/16514687.html">https://www.cnblogs.com/mimistudy/p/16514687.html</a></p>
<p>或者自行百度来寻找比较好理解的文章.</p>
<p>读取yaml文件, 我们需要安装 <code>pip install pyyaml</code></p>
<p>下面展示一些封装好的函数</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> yaml<br><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">read_yaml</span>(<span class="hljs-params">filename</span>):<br>    <span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">    将yaml文件中的数据读取出来</span><br><span class="hljs-string">    &quot;&quot;&quot;</span><br>    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(filename, encoding=<span class="hljs-string">&quot;utf-8&quot;</span>) <span class="hljs-keyword">as</span> file:<br>        data = yaml.full_load(file)<br>        <span class="hljs-keyword">return</span> data<br>    <br><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">data_to_yaml</span>(<span class="hljs-params">filename, data</span>):<br>    <span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">    将python中的字典或者列表写入一个yaml文件</span><br><span class="hljs-string">    &quot;&quot;&quot;</span><br>    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(filename, mode=<span class="hljs-string">&quot;a+&quot;</span>, encoding=<span class="hljs-string">&#x27;utf-8&#x27;</span>) <span class="hljs-keyword">as</span> file:<br>        yaml.dump(data=data, stream=file, allow_unicode=<span class="hljs-literal">True</span>, encoding=<span class="hljs-string">&#x27;utf-8&#x27;</span>)<br></code></pre></td></tr></table></figure>


<h1 id="操作excel"><a href="#操作excel" class="headerlink" title="操作excel"></a>操作excel</h1><p>python有两个比较有名的操作excel的第三方库:</p>
<ul>
<li>xlrd, 用来读取</li>
<li>xlwt, 用来写入</li>
</ul>
<p>这两个库呢, 基本上可以支持任何对excel的常规操作</p>
<p>但是这两个库, 都是最基本的api, 所有的逻辑都需要自己去设计, 十分的不方便.</p>
<p>当然, 也有人觉得, 自己去设计逻辑, 是一种十分稳定的程序编写方式.</p>
<p>对于新手来说, 直接学习一些封装好的库是更加有效的方式.</p>
<p>这里我们介绍的是 <strong>openpyxl</strong>, 安装: <code>pip install openpyxl</code></p>
<h2 id="读取"><a href="#读取" class="headerlink" title="读取"></a>读取</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> openpyxl<br><br>filePath = <span class="hljs-string">&quot;./test.xlsx&quot;</span>  <span class="hljs-comment"># excel路径</span><br>workBook = openpyxl.load_workbook(filePath)  <span class="hljs-comment"># 加载一个已有的excel</span><br><br>sheet = workBook.worksheets[<span class="hljs-number">0</span>]  <span class="hljs-comment"># 获取第一个sheet</span><br><span class="hljs-comment"># sheet = workBook[&#x27;Sheet1&#x27;]  # 根据sheet名称获取</span><br><br>maxRow = sheet.max_row  <span class="hljs-comment"># 获取内容的行数</span><br>maxCol = sheet.max_column  <span class="hljs-comment"># 获取内容的列数</span><br><br><span class="hljs-built_in">print</span>(maxRow)<br><span class="hljs-built_in">print</span>(maxCol)<br><br><span class="hljs-comment"># openxl中, 行和列都是直接从1开始计算</span><br>cellValue = sheet.cell(row=<span class="hljs-number">1</span>, column=<span class="hljs-number">1</span>).value  <span class="hljs-comment"># 根据行和列, 指定获取单元格内容</span><br><br><span class="hljs-built_in">print</span>(cellValue)<br></code></pre></td></tr></table></figure>

<h2 id="生成"><a href="#生成" class="headerlink" title="生成"></a>生成</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> openpyxl<br><br>filePath = <span class="hljs-string">&quot;./test123.xlsx&quot;</span>  <span class="hljs-comment"># excel路径</span><br><br>workBook = openpyxl.Workbook()  <span class="hljs-comment"># 可以创建一个excel文件, 如果已经存在, 则会进行内容覆盖</span><br><br>sheet = workBook.active  <span class="hljs-comment"># 获取当前编辑的表, 如果是一张新文件, 就是默认第一个sheet</span><br><br>sheet.title = <span class="hljs-string">&quot;test&quot;</span> <span class="hljs-comment"># 修改表名</span><br><br>sheet.cell(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>).value = <span class="hljs-number">1</span><br><br>workBook.save(filePath)<br></code></pre></td></tr></table></figure>

<h2 id="创建新表"><a href="#创建新表" class="headerlink" title="创建新表"></a>创建新表</h2><p>创建新表不论你使用的是 <code>load_workbook</code> 或者是 <code>Workbook</code> 都是可以的.</p>
<p>创建后, 其他写入操作的api都一样.</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> openpyxl<br><br>filePath = <span class="hljs-string">&quot;./test123.xlsx&quot;</span>  <span class="hljs-comment"># excel路径</span><br><br>workBook = openpyxl.Workbook()  <span class="hljs-comment"># 可以创建一个excel文件, 如果已经存在, 则会进行内容覆盖</span><br><br>sheet = workBook.create_sheet(<span class="hljs-string">&quot;表名&quot;</span>)<br>workBook.save(filePath)  <span class="hljs-comment"># 编辑后记得要保存</span><br></code></pre></td></tr></table></figure>

<h2 id="编辑"><a href="#编辑" class="headerlink" title="编辑"></a>编辑</h2><p>我们可以直接通过 <code>load_workbook</code> 的方式来编辑一张已存在的表</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> openpyxl<br><br>filePath = <span class="hljs-string">&quot;./test123.xlsx&quot;</span>  <span class="hljs-comment"># excel路径</span><br><br>workBook = openpyxl.load_workbook(filePath)<br><br>sheet = workBook.worksheets[<span class="hljs-number">0</span>]  <span class="hljs-comment"># 获取第一张表</span><br><br><span class="hljs-comment"># openxl中, 行和列都是直接从1开始计算</span><br>sheet.cell(row=<span class="hljs-number">1</span>, column=<span class="hljs-number">1</span>).value = <span class="hljs-number">2</span><br>sheet.cell(row=<span class="hljs-number">1</span>, column=<span class="hljs-number">3</span>).value = <span class="hljs-number">123</span><br><br>workBook.save(filePath)  <span class="hljs-comment"># 编辑后记得要保存</span><br></code></pre></td></tr></table></figure>


<h1 id="邮件"><a href="#邮件" class="headerlink" title="邮件"></a>邮件</h1><p>发送邮件有很多第三方库, 这里介绍一个我个人觉得比较好用的 <code>Zmail</code></p>
<blockquote>
<p>Zmail仅支持python3. 不支持python2.<br>pip install zmail</p>
</blockquote>
<ul>
<li>特性 <ul>
<li>自动寻找服务器地址以及端口</li>
<li>自动使用可靠的链接协议</li>
<li>自动将一个python字典映射成MIME对象（带有附件的）</li>
<li>自动添加头文件以及localhostname来避免服务器拒收你的邮件</li>
<li>轻松自定义你的头文件</li>
<li>支持使用HTML作为邮件内容</li>
<li>仅需python&gt;=3.5，你可以将其嵌入你的项目而无需其他的依赖</li>
</ul>
</li>
<li>使用须知<ul>
<li>使用Python3</li>
<li>确保打开了邮箱的POP3和SMTP功能 </li>
</ul>
</li>
</ul>
<h2 id="发送邮件"><a href="#发送邮件" class="headerlink" title="发送邮件"></a>发送邮件</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> zmail<br><br><span class="hljs-comment"># 你的邮件内容</span><br>mail_content = &#123;<br>    <span class="hljs-string">&quot;subject&quot;</span>:<span class="hljs-string">&quot;success!&quot;</span>,  <span class="hljs-comment"># 邮件主题</span><br>    <span class="hljs-string">&quot;content_text&quot;</span>: <span class="hljs-string">&quot;This message from zmail&quot;</span>, <span class="hljs-comment"># 邮件内容</span><br>    <span class="hljs-string">&quot;attachments&quot;</span>: <span class="hljs-string">&quot;&quot;</span>,  <span class="hljs-comment"># 邮件附件, 写上正确路径</span><br>&#125;<br><span class="hljs-comment"># 使用你的邮件账户名和授权码/密码登录服务器</span><br>server = zmail.server(<span class="hljs-string">&quot;yourEmail@163.com&quot;</span>, <span class="hljs-string">&quot;your password&quot;</span>)  <br><br><span class="hljs-built_in">print</span>(server.smtp_able())  <span class="hljs-comment"># 查看是否登录成功, True/False</span><br><br><span class="hljs-comment"># 发送邮件，可以使用元组重命名</span><br><span class="hljs-comment"># cc为抄送人</span><br>server.send_mail([<span class="hljs-string">&quot;yourEmail@qq.com&quot;</span>], mail_content, cc=(<span class="hljs-string">&quot;yourEmail@qq.com&quot;</span>)) <br><br><span class="hljs-comment"># 发送多个人, 可以是元组也可以是列表</span><br><span class="hljs-comment"># server.send_mail([&quot;yourEmail@qq.com&quot;, &quot;yourEmail@qq.com&quot;], mail_content, cc=(&quot;yourEmail@qq.com&quot;, &quot;&quot;yourEmail@qq.com&quot;&quot;)) </span><br></code></pre></td></tr></table></figure>

<h3 id="自定义server"><a href="#自定义server" class="headerlink" title="自定义server"></a>自定义server</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-comment"># 如果zmail不能正常工作，你可以自定义server的配置</span><br>server =zmail.server( <br>    <span class="hljs-string">&#x27;yourEmail@163.com&#x27;</span>,<br>    <span class="hljs-string">&#x27;your password&#x27;</span>,<br>    smtp_host=<span class="hljs-string">&#x27;smtp.163.com&#x27;</span>,<br>    smtp_port=<span class="hljs-number">994</span>,<br>    smtp_ssl=<span class="hljs-literal">True</span>,<br>    pop_host=<span class="hljs-string">&#x27;pop.163.com&#x27;</span>,<br>    pop_port=<span class="hljs-number">995</span>,<br>    pop_tls=<span class="hljs-literal">True</span><br>)<br></code></pre></td></tr></table></figure>

<h2 id="收件"><a href="#收件" class="headerlink" title="收件"></a>收件</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> zmail<br><br><span class="hljs-comment"># 你的邮件内容</span><br>mail_content = &#123;<br>    <span class="hljs-string">&quot;subject&quot;</span>:<span class="hljs-string">&quot;success!&quot;</span>,  <span class="hljs-comment"># 邮件主题</span><br>    <span class="hljs-string">&quot;content_text&quot;</span>: <span class="hljs-string">&quot;This message from zmail&quot;</span>, <span class="hljs-comment"># 邮件内容</span><br>    <span class="hljs-string">&quot;attachments&quot;</span>: <span class="hljs-string">&quot;&quot;</span>,  <span class="hljs-comment"># 邮件附件, 写上正确路径</span><br>&#125;<br><span class="hljs-comment"># 使用你的邮件账户名和授权码/密码登录服务器</span><br>server = zmail.server(<span class="hljs-string">&quot;yourEmail@163.com&quot;</span>, <span class="hljs-string">&quot;your password&quot;</span>)  <br><br>mail = server.get_latest()  <span class="hljs-comment"># 最新一封邮件  除此之外,还有多种收取的方式, 自行百度</span><br><br>zmail.show(mail)  <span class="hljs-comment"># 按照结构进行显示</span><br><br><span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">content-type: 邮件内容的类型</span><br><span class="hljs-string">subject: 邮件主题</span><br><span class="hljs-string">to：收件人</span><br><span class="hljs-string">from：寄件人</span><br><span class="hljs-string">date: 年-月-日 时间 时区</span><br><span class="hljs-string">boundary: 如果邮件为multiple - - - parts，你可以得到其分界线</span><br><span class="hljs-string">content: 邮件的文本内容（仅在text/plain时可以被解析）</span><br><span class="hljs-string">contents: 邮件的body,里面包含着由分界线分割的每一个段落</span><br><span class="hljs-string">attachments: None 或者 [[&#x27;附件名称;编码方式&#x27;,&#x27;附件的二进制内容&#x27;]...]</span><br><span class="hljs-string">id: 在邮箱中的id</span><br><span class="hljs-string">&quot;&quot;&quot;</span><br></code></pre></td></tr></table></figure>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/my-blog/categories/python/" class="category-chain-item">python</a>
  
  
    <span>></span>
    
  <a href="/my-blog/categories/python/Python%E5%9F%BA%E7%A1%80/" class="category-chain-item">Python基础</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/my-blog/tags/%E6%B5%8B%E8%AF%95%E5%BC%80%E5%8F%91/">#测试开发</a>
      
        <a href="/my-blog/tags/Python%E5%9F%BA%E7%A1%80/">#Python基础</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>python常用第三方库</div>
      <div>https://walker_kwu.gitee.io/my-blog/2023/03/25/python/base/python常用第三方库/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>木舟</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年3月25日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2023年5月23日</div>
        </div>
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="NC - 非商业性使用">
                <i class="iconfont icon-nc"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="SA - 相同方式共享">
                <i class="iconfont icon-sa"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/my-blog/2023/05/10/autoTest/pytest%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/" title="pytest基本使用">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">pytest基本使用</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/my-blog/2023/03/19/python/base/python%E5%B8%B8%E7%94%A8%E6%A0%87%E5%87%86%E5%BA%93/" title="python常用标准库">
                        <span class="hidden-mobile">python常用标准库</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <span>By 木舟</span> <i class="iconfont icon-love"></i> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/my-blog/js/events.js" ></script>
<script  src="/my-blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/my-blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/my-blog/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/my-blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
